package com.hz.framework.MyBean;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.hz.framework.dao.CommonSel;
import com.hz.supermanage.bean.HzsysPrograma;


public class ForValueBean extends TagSupport {

//	 * 代表控件必须有的属性
	private  String type; //标签属性 *
	private  String Parentvalue; //按钮显示名称 *
	private  String Sonvalue; //按钮事件 *
	
	private static String forValue="";
	/***
	 * @author 韩飞
	 * @time 2011-01-11	
	 * @throws JspException 
	 * 方法功能: 根据不同标识返回不同信息
	 */
	public int doEndTag() throws JspException {
		ServletRequest request = pageContext.getRequest();
		HttpSession session = pageContext.getSession();
		try {
			String se_parentlink = session.getAttribute("parentlink")==null?"":(String)session.getAttribute("parentlink");
			String se_sonlink = session.getAttribute("sonlink")==null?"":(String)session.getAttribute("sonlink");
			Parentvalue = request.getParameter("parentlink")==null?"":request.getParameter("parentlink");
			Sonvalue = request.getParameter("sonlink");
			if(!"".equals(Parentvalue)){
				if(!se_parentlink.equals(Parentvalue) || !se_sonlink.equals(Sonvalue)){
					session.setAttribute("parentlink", Parentvalue);
					session.setAttribute("sonlink", Sonvalue);
				}
			}else{
				Parentvalue = se_parentlink;
				Sonvalue = se_sonlink;
			}
			pageContext.getOut().println(forValue());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
//	返回相关信息
	public String forValue() {
		if("title".equals(type)){
			forValue = SelValue(type,Parentvalue)+"-"+SelValue(type,Sonvalue);
		}
		return forValue;
	}
	
	//查询相关信息
	public String SelValue(String flag,String forid) {
		CommonSel cs = new CommonSel();
		String back = "";
		if("title".equals(type)&& forid != null&& !"".equals(forid)){
			HzsysPrograma obj =  (HzsysPrograma)cs.hibernateGet(HzsysPrograma.class, Integer.parseInt(forid));
			if(obj!=null){
				back = obj.getProname();
			}
		}
		return back;
	}
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
}